//
//  main.swift
//  Victoria3
//
//  Created by lhc on 2023/11/1.
//

import Foundation


func profit(_ consume: [(Int, Goods)], _ produce: [(Int, Goods)]) -> Int {
    let cost = consume.reduce(0) { partialResult, ng in
        return partialResult + ng.0 * ng.1.price
    }
    
    let income = produce.reduce(0) { partialResult, ng in
        return partialResult + ng.0 * ng.1.price
    }
    

    
    return income - cost
}

var result: [(String, Int)] = []

for mode in ProductionMode.allCases {
    
    result.append((mode.rawValue, profit(mode.raw(), mode.process())))
}

result.sort { left, right in
    return left.1 > right.1
}


result.forEach { r in
//    print("- \(r.0) \(r.1)")
    print("| \(r.0) | \(r.1) |" )
}

print("\n\n")
print("---------- 食品厂分类 ----------")

let foodResult = ProcessedFoodFactory.calculate()
foodResult.forEach { r in
    print("| \(r.0) | \(r.1) |")
}

